<?php

class System_Form_ProblemInput extends Zend_Form
{

    public function init()
    {
        $this->setName('problem_form');
        parent::init();
        
        $this->setMethod('POST');
        $this->setAttrib('enctype', 'multipart/form-data');
        
        $title = new Zend_Form_Element_Text('title');
        $title->setLabel('Маселе аты:')
                ->setRequired(true)
                ->addValidator('NotEmpty')
                ->setAttrib('rows', 5)
                ->addFilter('StringTrim')
                ->addValidator('Db_NoRecordExists', FALSE, array(
                    'table' => 'problems',
                    'field' => 'title'
                ))
                ->addValidator('Alnum');
        $this->addElement($title);
        
        
        $body = new Zend_Form_Element_Textarea('body');
        $body->setLabel('Маселненин берилиш:')
                ->setRequired(true)
                ->setAttrib('rows', 5)
                ->addValidator('NotEmpty')
                ->addFilter('StringTrim');
        $this->addElement($body);
        
        
        $input = new Zend_Form_Element_Textarea('input');
        $input->setLabel('Кирүүчү берилиштер:')
                ->setRequired(true)
                ->setAttrib('rows', 5)
                ->addValidator('NotEmpty')
                ->addFilter('StringTrim');
        $this->addElement($input);
        
        
        $output = new Zend_Form_Element_Textarea('output');
        $output->setLabel('Чыгуучу берилиштер:')
                ->setRequired(true)
                ->setAttrib('rows', 5)
                ->addValidator('NotEmpty')
                ->addFilter('StringTrim');
        $this->addElement($output);
        
        $file = new Zend_Form_Element_File('file');
        $file->setLabel('Тест:')
                ->setRequired(true)
                ->setDestination(APPLICATION_PATH.DIRECTORY_SEPARATOR.'modules'. DIRECTORY_SEPARATOR.'system'.DIRECTORY_SEPARATOR . 'data'. DIRECTORY_SEPARATOR . 'uploads'. DIRECTORY_SEPARATOR)
                ->addValidator('Size', false, 1024000)
                ->addValidator('Extension', false, 'xml');
                
        $this->addElement($file);
        
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Киргизүү')
                ->setAttrib('claas', 'button_big');
        $this->addElement($submit);
        
    }
    
    public function addElement($element, $name = null, $options = null) {
        parent::addElement($element, $name, $options);
        
        if (!isset($name) || $name == null){
            $name = $element->getName();
        }
        
        if (isset($this->_elements[$name])) {
            $this->_elements[$name]->removeDecorator('Label');
            $this->_elements[$name]->removeDecorator('HtmlTag');
            $this->_elements[$name]->removeDecorator('DtDdWrapper');
            $this->_elements[$name]->removeDecorator('Description');
            $this->_elements[$name]->setAttrib('placeholder', $this->_elements[$name]->getLabel());
        }
        
    }

}

